

function getXHR() {
	var xhr = false;
	var XMLHttpPossibilities = [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];
	var xhrPossibilitiesLen = XMLHttpPossibilities.length
	for (var i=0; i < xhrPossibilitiesLen; i++) {
		try { xhr = XMLHttpPossibilities[i](); }
		catch (e) {	continue; }
		break;
	}
	return xhr;
}



function makeAJAXRequest(url, callBack, callDuring, attrs) {
	if (!attrs) { attrs = {}; }
	var xhrObj = getXHR();
	var reqType = (attrs['post']) ? 'POST' : 'GET';
	xhrObj.open(reqType, url, true);
	if (attrs['post']) { xhrObj.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); }
	xhrObj.onreadystatechange = function() {
		if (xhrObj.readyState != 4) { if (callDuring) { callDuring(); } return; } /* during req */
		if (xhrObj.status != 200) { alert('HTTP error ' + xhrObj.status); return; } /* buss a error and cut */
		if (attrs['responseType'] == 'text' || attrs['responseType'] == 'json') { callBack(xhrObj.responseText); } /* every thing irie mon...work pan it nuh! */
		else { callBack(xhrObj.responseXML); }
		return;
	};
	xhrObj.send(attrs['post']);
}


function AJAXInteraction(url, callBack, callDuring, responseText) {

	var req = getXHR();
	req.onreadystatechange = function() {
		if (req.readyState != 4) { if (callDuring) { callDuring(); } return; } /* during req */
		if (req.status != 200) { alert('HTTP error ' + req.status); return; } /* buss a error and cut */
		if (responseText) { callBack(req.responseText); } /* every thing irie mon...work pan it nuh! */
		else { callBack(req.responseXML); }
		return;
	}

	this.doGet = function() {
		req.open("GET", url, true);
		req.send(null);
	}

	this.doReq = function(post) {
		if (post) { req.open("POST", url, true); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); }
		else { req.open("GET", url, true); }
		req.send(post);
	}

	this.doPost = function(body) {
		req.open("POST", url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send(body);
	}
}


function sendRequest(url,callback,postData) {
	var req = getXhr();
	if (!req) { return; }
	var method = (postData) ? 'POST' : 'GET';
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData) { req.setRequestHeader('Content-type','application/x-www-form-urlencoded'); }
	req.onreadystatechange = function () {
		if (req.readyState != 4) { return; }
		if (req.status != 200 && req.status != 304) {
			alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) { return; }
	req.send(postData);
}